
	mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:false,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
	});
	
	
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var currenPage=1;
    var pageSize=10;
    var total_page=0;
    var total_count=0;
    var other_id=0;
    var other_name='';
    
    window.onload = function(){
			 mui.plusReady(function(){
			    other_id=plus.webview.currentWebview().other_id;
			    other_name=plus.webview.currentWebview().other_name;
			    document.getElementById('from_info').innerHTML=other_name+'（ID：'+other_id+'）';
			    
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			    
			    mui.ajax({
					url: apiurl + "Article/book_ulist_detail/",
					data: {'p':currenPage,'size':pageSize,'user_id':uid,'other_id':other_id,'_token':userinfo.token},
					async: true,
					dataType: 'json',
					crossDomain: true, //强制使用5+跨域
					type: 'get',
					timeout: 10000,
					success: function(res) {
						console.log(JSON.stringify(res));
						// 请求成功
						if(res.status ==-3){
							mui.toast(res.msg);
							app.out();
							return false;
						} else {
							total_page=res.total_page;
							total_count=res.sum;
							var htm=get_data(res.resource);
							$('#pullrefresh .mui-scroll #business').append(htm);
						}
					},
					error: function(xhr, type, errorThrown) {
						//console.log(JSON.stringify(xhr));
						//console.log(JSON.stringify(type));
						//console.log(JSON.stringify(errorThrown));
						mui.toast('获取数据失败！');
					}
				});
			
			
			    document.getElementById('send_msg').addEventListener('tap', function() {
					var Info={
						user_id: uid,
						other_id: other_id,
						etype: 3,
						content: document.getElementById('message').value.trim(),
						_token:userinfo.token
					};
					
					if(Info.content==''){
						mui.alert('发送内容不能为空');
						return false;
					}
					mui.ajax({
						url: apiurl + "Article/add_book/",
						data: Info,
						async: true,
						dataType: 'json',
						crossDomain: true, //强制使用5+跨域
						type: 'post',
						timeout: 10000,
						success: function(res) {
							console.log(JSON.stringify(res));
							if(res.status ==-3){
								mui.toast(res.msg);
								app.out();
								return false;
							}
							// 请求成功
							if(res.status == 0) {
								mui.toast(res.msg);
							} else {
								mui.toast(res.msg);
								document.getElementById('message').value='';
								location.href=location;
							}
						},
						error: function(xhr, type, errorThrown) {
							//console.log(JSON.stringify(xhr));
							//console.log(JSON.stringify(type));
							//console.log(JSON.stringify(errorThrown));
							mui.toast('操作失败！');
						}
					});
					
				}, false);
		
			});

    }

    function get_data(data){
    	var htm='';
    	if(data.length==0){
    		return htm;
    	}
		for(i in data) {
			/*
			 * <!--来自自己-->
				<div style="border-bottom:1px solid #ccc;">
					<div class="mui-card-footer">
						我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，我是来自自己的消息，。
					</div>
					<div style="text-align:right;color:#666;font-size:12px;line-height: 16px;padding-right:5px;;">2018-09-12 12:00:00</div>
				</div>
			 */
			if(data[i]['receive_id']==uid){
				htm+='<div class="mui-card-content" style="border-bottom:1px solid #ccc;">';
				htm+='<div class="mui-card-content-inner" style="color:#0a6999;">';
				htm+=data[i]['content'];
				htm+='</div>';
				htm+='<div style="text-align:right;font-size:12px;line-height: 16px;padding-right:5px;;">'+data[i]['add_time']+'</div>';
			    htm+='</div>';
			}
			else{
				htm+='<div style="border-bottom:1px solid #ccc;">';
				htm+='<div class="mui-card-footer">';
				htm+=data[i]['content'];
				htm+='</div>';
				htm+='<div style="text-align:right;color:#666;font-size:12px;line-height: 16px;padding-right:5px;;">'+data[i]['add_time']+'</div>';
			    htm+='</div>';
			}
	   }
		return htm;
    }


	function pullupRefresh() {
		setTimeout(function() {
			currenPage++;
			mui.ajax({
				url: apiurl + "Article/book_ulist_detail/",
				data: {'p':currenPage,'size':pageSize,'user_id':uid,'other_id':other_id,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll #business').append(htm);
					}
					
					if(currenPage < total_page){
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    /*能上拉*/
	                }else{
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);/*不能上拉*/
	                }
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
		}, 1500);
	}
	
